Skip to content

tests: pin multisig no-descriptor and consolidation behaviour in PSBTParser#933

Open
nkatha23 wants to merge 1 commit into
SeedSigner:devfrom
nkatha23:tests/psbt-parser-targeted-cases
Open

tests: pin multisig no-descriptor and consolidation behaviour in PSBTParser#933
nkatha23 wants to merge 1 commit into
SeedSigner:devfrom
nkatha23:tests/psbt-parser-targeted-cases

Conversation

@nkatha23
Copy link
Copy Markdown

@nkatha23 nkatha23 commented May 7, 2026

In response to issue #931 , this is what I found:

Reading through PSBTParser._parse_outputs(), I noticed two spending scenarios that weren't covered by the existing test suite:

  1. Multisig PSBT with no witness script in the output scope. Some coordinators produce PSBTs where the output scopes contain only the bare scriptPubKey, no witness_script, no redeem_script. The parser can't reconstruct the multisig
    policy from a bare script hash, so it has no way to verify that the output belongs to the wallet. The safe, correct behaviour is to treat it as an external spend. That path existed in the code but was never exercised by a test, meaning a future refactor could silently break it.
  2. Consolidation where every output is internal. A PSBT that sends everything backto the same wallet, split across a change-branch address (1/) and a receive-branch address (0/) should produce spend_amount == 0. The parser
    classifies any output as internal when the derived key matches the output scriptPubKey, regardless of branch index. Again, this worked but wasn't tested.

so this PR adds:
Two new test methods inside TestPSBTParser in tests/test_psbt_parser.py:
test_multisig_no_descriptor_all_outputs_are_spend- covers all three multisig script types. Strips witness_script and redeem_script from the output scope and pins that num_change_outputs == 0 with everything treated as spend.
test_consolidation_all_outputs_internal- covers all seven supported script types. Two internal outputs (change-branch + receive-branch) both belonging to the signing wallet, pins spend_amount == 0 and change_amount == input_amount - fee.

@nkatha23 nkatha23 marked this pull request as draft May 7, 2026 11:22
@nkatha23 nkatha23 force-pushed the tests/psbt-parser-targeted-cases branch from b91a825 to 28c700f Compare May 7, 2026 11:26
@nkatha23 nkatha23 marked this pull request as ready for review May 7, 2026 11:26
@nkatha23 nkatha23 force-pushed the tests/psbt-parser-targeted-cases branch from 28c700f to 976f78b Compare May 7, 2026 11:30
When a coordinator strips witness_script/redeem_script from multisig output
scopes, _get_policy() returns a bare policy dict with no m/n/cosigners, which
never matches the input policy — so no output is classified as change and all
value shows as spend_amount. This was the correct conservative behaviour but
had no test pinning it.

Also adds a consolidation test: a PSBT where both a change-branch (1/*) and a
receive-branch (0/*) output belong to the signing wallet. PSBTParser classifies
both as internal regardless of branch index, giving spend_amount == 0.

Covers all three multisig types for the no-descriptor case, all seven script
types for the consolidation case. Part of SeedSigner#931.
@nkatha23 nkatha23 force-pushed the tests/psbt-parser-targeted-cases branch from 976f78b to 0e71f30 Compare May 11, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant